package chapter3_array;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @Author yuh
 * @Date Created in 上午7:45 2018/4/9
 * @Description 写程序 简单第一
 */
public class JsonPattern {

    static Pattern pattern = Pattern.compile("\\{.*?\"name\":\"(.*)\",\"age\":(.*).*?\\}");
    static Pattern pattern1 = Pattern.compile("\"name\":\"[a-zA-Z]*\",\"age\":[0-9]{0,3}");
    static StringBuffer buffer = new StringBuffer();

    public static void main(String[] args) {
        String jsonStr = "[{\"hobbies\":\"huabing\",\"name\":\"yuhao\",\"age\":},{\"hobbies\":\"huabing\",\"name\":\"yuhao\",\"age\":24},{\"hobbies\":\"huabing\",\"name\":\"yuhao\",\"age\":24},{\"hobbies\":\"huabing\",\"name\":\"yuhao\",\"age\":24}]";
       /* Matcher matcher = pattern.matcher(jsonStr);
        while(matcher.find()){
            System.out.println(matcher.group(1)+"\t"+matcher.group(2));
        }*/
        System.out.println(getSubJson(jsonStr));
    }

    static String getSubJson(String originalStr){
        buffer.append("{");
        Matcher matcher = pattern1.matcher(originalStr);
        while(matcher.find()){
            System.out.println(matcher.group());
        }
        buffer.append("}");
        return buffer.toString();
    }
}
